﻿using Fast.ConfigureOptions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;

namespace Fast.DynamicApiController
{
    /// <summary>
    /// 动态Api控制器选项
    /// </summary>
    [SkipScan]
    public class DynamicApiControllerOptions : IConfigureOptions<DynamicApiControllerOptions>
    {
        /// <summary>
        /// 默认区域
        /// </summary>
        public string DefaultArea { get; set; }

        /// <summary>
        /// 默认 HTTP 谓词
        /// <para></para>
        /// 默认为 "POST"
        /// </summary>
        public string DefaultHttpVerb { get; set; }

        /// <summary>
        /// 默认 API 路由前缀
        /// </summary>
        public string DefaultRoutePrefix { get; set; }

        /// <summary>
        /// 删除动态API控制器后缀
        /// </summary>
        public string[] RemoveControllerPostfixes { get; set; }

        /// <summary>
        /// 删除动态 API 方法后缀
        /// </summary>
        public string[] RemoveActionPostfixes { get; set; }

        /// <summary>
        /// 是否删除 Action 前缀
        /// </summary>
        public bool? HasRemoveActionPrefix { get; set; }

        /// <summary>
        /// 是否小写路由
        /// </summary>
        public bool? HasLowercaseRoute { get; set; }

        /// <summary>
        /// 是否驼峰命名
        /// </summary>
        public bool? HasCamelCase { get; set; }

        public void PostConfigure(DynamicApiControllerOptions options, IConfiguration configuration)
        {
            RemoveControllerPostfixes ??= new string[] { "AppService", "ApplicationService", "Services", "Service", "ApiController", "Controller" };
            RemoveActionPostfixes = new string[] { "Async" };
            DefaultHttpVerb ??= "POST";
            DefaultRoutePrefix ??= "api";
            HasRemoveActionPrefix ??= true;
            HasLowercaseRoute ??= true;
            HasCamelCase ??= false;
        }
    }
}
